package com.biz.primus.ms.commodity.dao.po;

import com.biz.primus.base.enums.vendor.VendorType;
import com.biz.primus.commodity.enums.ProductAuditStatus;
import com.biz.primus.commodity.vo.backend.IProductAuditVo;
import com.biz.primus.ms.base.jpa.converter.ListStringConverter;
import com.biz.primus.ms.base.jpa.po.BaseEntity;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

/**
 * 商品审核 (用于平台端记录商家端提交的商品)
 *
 * @author david-liu
 * @date 2016年12月22日
 * @reviewer
 * @see
 */
@Data
@Entity
@Table(name = "pro_product_audit")
public class ProductAudit extends BaseEntity {

    private static final long serialVersionUID = 2778482748988267272L;

    /**
     * 商品 ID(创建审核记录之前, 创建好商品 ID)
     */
    private Long productId;

    /**
     * 商家 ID
     */
    @Column(nullable = false)
    private Long vendorId;

    /**
     * 商家名称,冗余
     */
    @Column(nullable = false)
    private String vendorName;

    /**
     * 商品名称
     */
    @Column(length = 255, nullable = false)
    private String name;

    /**
     * 商品子标题
     */
    @Column(length = 50)
    private String subTitle;

    /**
     * 商品编码
     */
    @Column(length = 50, nullable = false)
    private String productCode;

    /**
     * 商家自定义商品编码
     */
    @Column(length = 50)
    private String vendorProductCode;

    /**
     * 商品简介
     */
    @Column
    private String breif;

    /**
     * 商品品牌
     */
    @ManyToOne
    @JoinColumn(name = "brand_id")
    private Brand brand;

    /**
     * 商品分类
     */
    @ManyToOne
    @JoinColumn(name = "category_id")
    private Category category;

    /**
     * 商品介绍
     */
    @Column(columnDefinition = "TEXT")
    @Convert(converter = ListStringConverter.class)
    private List<String> introImages;

    /**
     * 商品 Logo
     */
    @Column
    private String logo;

    /**
     * 商品重量(单位: 克)
     */
    @Column
    private Integer weight;

    /**
     * 商品轮播图
     */
    @Column(columnDefinition = "TEXT")
    @Convert(converter = ListStringConverter.class)
    private List<String> images;

    @ManyToMany
    @JoinTable(name = "pro_sale_tag_product_audit",
            joinColumns = {@JoinColumn(name = "product_audit_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "sale_tag_id", referencedColumnName = "id")})
    private List<SaleTag> saleTags;


    /**
     * SEO 关键字信息
     */
    @Column
    private String seoKeywords;


    /**
     * 商品审核状态
     */
    @Enumerated(value = EnumType.STRING)
    private ProductAuditStatus auditStatus;

    /**
     * 审核备注
     */
    @Column(columnDefinition = "TEXT")
    private String auditMessage;

    /**
     * 商品是否被平台端锁定
     */
    @Column
    private Boolean locked;

    /**
     * 商品平台类型
     */
    @Column
    @Enumerated(EnumType.STRING)
    private VendorType productType;

    /**
     * 删除标识
     */
    @Column
    private Boolean deleteFlag = Boolean.FALSE;

    /**
     * 基于 Vo构建 Po
     *
     * @param vo vo
     */
    public void fromVo(IProductAuditVo vo) {
        this.setName(vo.getName());
        this.setSubTitle(vo.getSubTitle());
        this.setVendorProductCode(vo.getProductCode());
        this.setBreif(vo.getBreif());
        this.setLogo(vo.getLogo());
        this.setImages(vo.getImages());
        this.setIntroImages(vo.getIntroImages());
        this.setSeoKeywords(vo.getSeoKeywords());
        this.setWeight(vo.getWeight());
        this.setProductType(vo.getType());
    }

}
